package com.ruoyi.carowner.service.impl;

import java.util.List;

import com.ruoyi.carowner.domain.CarownerWallet;
import com.ruoyi.carowner.domain.CarownerWxpay;
import com.ruoyi.carowner.service.ICarownerWalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.carowner.mapper.CarownerZfbpayMapper;
import com.ruoyi.carowner.domain.CarownerZfbpay;
import com.ruoyi.carowner.service.ICarownerZfbpayService;

/**
 * 车主支付宝支付Service业务层处理
 *
 * @author ruoyi
 * @date 2024-08-19
 */
@Service
public class CarownerZfbpayServiceImpl implements ICarownerZfbpayService {
    @Autowired
    private CarownerZfbpayMapper carownerZfbpayMapper;

    @Autowired
    private ICarownerWalletService carownerWalletService;

    /**
     * 查询车主支付宝支付
     *
     * @param id 车主支付宝支付主键
     * @return 车主支付宝支付
     */
    @Override
    public CarownerZfbpay selectCarownerZfbpayById(Integer id) {
        return carownerZfbpayMapper.selectCarownerZfbpayById(id);
    }

    @Override
    public CarownerZfbpay selectZfbpayByUserId(Integer user_id) {
        return carownerZfbpayMapper.selectZfbpayByUserId(user_id);
    }

    /**
     * 查询车主支付宝支付列表
     *
     * @param carownerZfbpay 车主支付宝支付
     * @return 车主支付宝支付
     */
    @Override
    public List<CarownerZfbpay> selectCarownerZfbpayList(CarownerZfbpay carownerZfbpay) {
        return carownerZfbpayMapper.selectCarownerZfbpayList(carownerZfbpay);
    }

    /**
     * 新增车主支付宝支付
     *
     * @param carownerZfbpay 车主支付宝支付
     * @return 结果
     */
    @Override
    public int insertCarownerZfbpay(CarownerZfbpay carownerZfbpay) {
        return carownerZfbpayMapper.insertCarownerZfbpay(carownerZfbpay);
    }

    /**
     * 修改车主支付宝支付
     *
     * @param carownerZfbpay 车主支付宝支付
     * @return 结果
     */
    @Override
    public int updateCarownerZfbpay(CarownerZfbpay carownerZfbpay) {

        CarownerWallet carownerWallet = carownerWalletService.selectCarownerWalletById(carownerZfbpay.getId());
        carownerWallet.setBalance(carownerWallet.getBalance() + carownerZfbpay.getPaymoney());
        carownerWallet.setPaymoney(carownerZfbpay.getPaymoney());
        carownerWallet.setPaytype(1);
        carownerWallet.setUserId(carownerZfbpay.getUserId());
        carownerWallet.setTransstatus(0);
        carownerWalletService.updateCarownerWallet(carownerWallet);


        return carownerZfbpayMapper.updateCarownerZfbpay(carownerZfbpay);
    }

    /**
     * 批量删除车主支付宝支付
     *
     * @param ids 需要删除的车主支付宝支付主键
     * @return 结果
     */
    @Override
    public int deleteCarownerZfbpayByIds(Integer[] ids) {
        return carownerZfbpayMapper.deleteCarownerZfbpayByIds(ids);
    }

    /**
     * 删除车主支付宝支付信息
     *
     * @param id 车主支付宝支付主键
     * @return 结果
     */
    @Override
    public int deleteCarownerZfbpayById(Integer id) {
        return carownerZfbpayMapper.deleteCarownerZfbpayById(id);
    }
}
